/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.stalinski.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;

public class Crypter {

    public static String crypt(String args) throws NoSuchAlgorithmException {
        /* Berechnung */
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(args.getBytes());
        byte[] result = md5.digest();

        /* Ausgabe */
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < result.length; i++) {
            hexString.append(Integer.toHexString(0xFF & result[i]));
        }
        System.out.println("MD5: " + hexString.toString());
        return hexString.toString();
    }

    public static int generatePIN() {
        Random rand = new Random();
        int rnd = 0;

        for(int i = 1000; i >= 1; i=i/10) {
            rnd += rand.nextInt(9)*i;
        }
        return rnd;
    }

    public static String generatePass(boolean nw) throws Exception {
        Random rand = new Random();
        String[] alphabet = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
            "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

        int rnd = 0;
        int evenOdd = 0;
        String pass = "";
        for (int i = 1; i <= 6; i++) {
            rnd = rand.nextInt(25);
            evenOdd = rand.nextInt(7);
            if (evenOdd == 0 || evenOdd == 3) {
                pass += alphabet[rnd].toLowerCase();
            } else if (evenOdd == 1 || evenOdd == 2) {
                pass += alphabet[rnd];
            } else {
                pass += ((rnd % 4) + 1);

            }
        }
        if (nw) {
            return pass;
        } else {
            return "notset";
        }
    }
}
